﻿using System.Collections.Generic;
using System.Linq;
using TeamCityMonitor.Models;

namespace TeamCityMonitor.Repository
{
    public interface ICacheStatisticsRepository
    {
        IEnumerable<CacheStatistics> GetAllStatistics();
    }

    public class CacheStatisticsRepository : ICacheStatisticsRepository
    {
        private StorageContext db = new StorageContext();

        public IEnumerable<CacheStatistics> GetAllStatistics()
        {
            return db.CacheStatistics.ToList();
        }

        public void Save(CacheStatistics cache)
        {
            if (cache.ID == -1)
            {
                db.CacheStatistics.Add(cache);
            }

            db.SaveChanges();
        }
    }
}